#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Background < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_defualt_variables
    bg = M3G::Background.new

    assert_equal true      , bg.depth_clear_enabled?
    assert_equal true      , bg.color_clear_enabled?
    assert_equal 0x00000000, bg.color
    assert_equal nil       , bg.image
    assert_equal M3G::Background::BORDER, bg.image_mode.x
    assert_equal M3G::Background::BORDER, bg.image_mode.y
  end

  def test_set_variables

    bg  = M3G::Background.new
    img = M3G::Image2D.new M3G::Image2D::RGBA, 64, 48

    bg.color              = 0xff345678
    bg.color_clear_enable = false
    bg.depth_clear_enable = false
    bg.image              = img
    bg.image_mode         = [M3G::Background::REPEAT, M3G::Background::REPEAT]
    bg.crop               = [1, 2, 100, 200]

    assert_equal false     , bg.depth_clear_enabled?
    assert_equal false     , bg.color_clear_enabled?
    assert_equal 0xff345678, bg.color
    assert_equal img       , bg.image
    assert_equal M3G::Background::REPEAT, bg.image_mode.x
    assert_equal M3G::Background::REPEAT, bg.image_mode.y
    assert_equal 1         , bg.crop.x
    assert_equal 2         , bg.crop.y
    assert_equal 100       , bg.crop.width
    assert_equal 200       , bg.crop.height
  end

  def test_duplicate
    bg1 = M3G::Background.new
    img = M3G::Image2D.new M3G::Image2D::RGBA, 64, 48

    bg1.color              = 0xff345678
    bg1.color_clear_enable = false
    bg1.depth_clear_enable = false
    bg1.image              = img
    bg1.image_mode         = [M3G::Background::REPEAT, M3G::Background::REPEAT]
    bg1.crop               = [1, 2, 100, 200]

    bg2 = bg1.duplicate

    assert_equal false     , bg2.depth_clear_enabled?
    assert_equal false     , bg2.color_clear_enabled?
    assert_equal 0xff345678, bg2.color
    assert_equal img       , bg2.image
    assert_equal M3G::Background::REPEAT, bg2.image_mode.x
    assert_equal M3G::Background::REPEAT, bg2.image_mode.y
    assert_equal 1         , bg2.crop.x
    assert_equal 2         , bg2.crop.y
    assert_equal 100       , bg2.crop.width
    assert_equal 200       , bg2.crop.height
  end

  def test_references
    bg  = M3G::Background.new
    img = M3G::Image2D.new M3G::Image2D::RGBA, 64, 48

    bg.image = img

    objs = bg.references

    assert_equal 1  , objs.length
    assert_equal img, objs[0]
  end

end

